package com.cat.model.biz.service.admin.impl;

import java.sql.SQLException;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alonew.core.commons.util.CommonUtil;
import com.alonew.db.dao.TxCommonDAO;
import com.cat.model.biz.logic.SystemLogic;
import com.cat.model.biz.service.admin.SystemService;
import com.cat.model.common.model.admin.AdminModuleVO;
import com.cat.model.common.model.admin.AdminRolePermissionVO;
import com.cat.model.common.model.admin.AdminRoleVO;
import com.cat.model.common.model.admin.AdminUser;
import com.cat.model.common.model.admin.AdminUserRoleVO;

@Service("systemService")
public class SystemServiceImpl implements SystemService{
	@Autowired
	private TxCommonDAO commonDAO;
	
	@Autowired
	private SystemLogic systemLogic;
	
	@Override
	public AdminUser addAdminUser(AdminUser vo) throws SQLException {
		vo.setPassword(CommonUtil.md5(vo.getPassword()));
		vo.setLoginTime(new Date());
		systemLogic.insertAdminUser(vo);
		return vo;
	}

	@Override
	public AdminUser updateAdminUser(AdminUser vo) throws SQLException {
		vo.setPassword(CommonUtil.md5(vo.getPassword()));
		systemLogic.updateAdminUser(vo, "username","password","sysCode");
		return vo;
	}
	
	@Override
	public AdminModuleVO addAdminModule(AdminModuleVO vo) throws SQLException {
		
		systemLogic.insertAdminModule(vo);
		
		return vo;
	}

	@Override
	public AdminModuleVO updateAdminModule(AdminModuleVO vo) throws SQLException {
		
		systemLogic.updateAdminModule(vo, "parentId","name","description","url","orderIndex","sysCode","enableFlag");
		return vo;
	}
	
	@Override
	public AdminRoleVO addAdminRole(AdminRoleVO vo) throws SQLException {
		
		systemLogic.insertAdminRole(vo);
		
		return vo;
	}

	@Override
	public AdminRoleVO updateAdminRole(AdminRoleVO vo) throws SQLException {
		
		systemLogic.updateAdminRole(vo,"name","description");
		return vo;
	}
	
	@Override
	public AdminRolePermissionVO insertAdminRolePermission(AdminRolePermissionVO vo) throws SQLException {
		
		systemLogic.insertAdminRolePermission(vo);
		
		return vo;
	}
	
	@Override
	public AdminUserRoleVO insertAdminUserRole(AdminUserRoleVO vo) throws SQLException {
		
		systemLogic.insertAdminUserRole(vo);
		
		return vo;
	}
}
